package com.wondertek.common.dict;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import java.lang.reflect.Field;

/**
 * @author xqs
 */
public class AutoDictUtil {

    public static void dict(Object obj){
        Field[] fields = ReflectUtil.getFields(obj.getClass());
        for (Field field : fields){
            AutoDict autoDict = field.getAnnotation(AutoDict.class);
            if(autoDict !=null){
                String type = autoDict.type();
                Object fieldValue = ReflectUtil.getFieldValue(obj, autoDict.field());
                String dictName = SpringUtil.getBean(AutoDictService.class).getDictName(type, fieldValue.toString());
                ReflectUtil.setFieldValue(obj,field,dictName);
            }
        }
    }
}
